#ifndef FONTMANAGER_H
#define FONTMANAGER_H

#include "Singleton.h"
#include "DX11VertexData.h"
#include "ConstantBuffer.h"

#include <stack>
#include <vector>
#include <string>
#include <map>
#include <d3d11.h>
#include <dxgi.h>
#include <D3DX10math.h>

class CharacterQuad
{
public:
	CharacterQuad();
	~CharacterQuad();
	void Initialise(D3DXVECTOR2 uv[]);

	void Translate(const D3DXVECTOR3& pos);
	void Rotate(float angle, D3DXVECTOR3 xyz);
	void SetColour(const D3DXVECTOR4& col);
	void Draw();

	void SetFont(const std::wstring& fontFilePath);

private:
	std::wstring m_texturePath;
	D3DXVECTOR2 m_uv;
	D3DXMATRIX m_world;

	std::stack<D3DXMATRIX> m_transformations;

	std::vector<VertexData> m_vertData;

	ID3D11Buffer* m_pVertexBuffer;
	ID3D11Buffer* m_pIndexBuffer;
	ID3D11Buffer* m_pConstantBuffer;
	ID3D11SamplerState* m_pTextureSamplerState;
	ID3D11ShaderResourceView* m_textureResource;

	ConstantBuffer m_cb;
	//std::wstring m_texture;
};

class Font
{
public:
	Font();
	bool Load();

	void Translate(int asciiChar, const D3DXVECTOR3& pos);
	void Scale(const D3DXVECTOR3& mat);
	void Draw(int asciiVal);
	void SetColour(int asciival, const D3DXVECTOR4& col);
	void SetFont(int asciiVal, const std::wstring& fontFilePath);
private:
	std::map<int, CharacterQuad> m_characters; //<ascii value, uv coordinate>
	D3DXVECTOR4 m_colour;
};

class FontManager : public Uncopyable
{
	FontManager();
	friend class Singleton<FontManager>;
public:
	~FontManager();
	bool LoadFont(const std::string& tag);

	void Translate(const std::string& tag, int asciiChar, const D3DXVECTOR3& pos);
	void Draw(const std::string& tag, int asciiChar);
	void SetColour(const std::string& tag, int asciichar , const D3DXVECTOR4& col);
	void SetFont(const std::string& tag, int asciichar,const std::wstring& fontFilePath);

private:
	std::map<std::string, Font*> m_fonts;
};

typedef Singleton<FontManager> TheFontManager;

#endif //FONTMANAGER_H